package demo3;

public class Text08 {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() -> {
            // 通过线程对象内部维护的中断标识，判断当前线程是否需要中断
            while (!Thread.currentThread().isInterrupted()) {
                // 线程中具体的任务是打印一句话
                System.out.println("hello thread...");
            }
            System.out.println("线程已退出");
        });

        System.out.println("线程是否存活：" + thread.isAlive());
        // 启动线程
        thread.start();
        System.out.println("线程是否存活：" + thread.isAlive());
        // 中断线程，发出中断信号
        thread.interrupt();
        // 等待线程销毁
        Thread.sleep(1000);
        // 查看是否存活
        System.out.println("线程是否存活：" + thread.isAlive());
    }
}
